﻿package src.fdezain.cardGame.shuffle
{

	/**
	 * ...
	 * @author FabricioDezain
	 */
	public class Shuffle
	{


		public static function Randomico (nMinimum:Number,nMaximum:Number=0,nRoundToInterval:Number=1):Number
		{

			if (nMinimum > nMaximum)
			{
				var nTemp:Number = nMinimum;
				nMinimum = nMaximum;
				nMaximum = nTemp;
			}

			var nDeltaRange:Number = nMaximum - nMinimum + 1 * nRoundToInterval;

			var nRandomNumber:Number = Math.random() * nDeltaRange;

			nRandomNumber += nMinimum;

			return Math.floor(nRandomNumber);
		}

		public static function add (aArray:Array):Array
		{
			var aCopy:Array=aArray.concat();
			var aRandomized:Array = new Array ();
			var oElement:Object;
			var nRandom:Number;
			var i:uint=0;
			for (i = 0; i < aCopy.length; i++)
			{
				nRandom=Randomico(0,aCopy.length-1);
				aRandomized.push (aCopy[nRandom]);
				aCopy.splice (nRandom,1);
				i--;
			}
			return aRandomized;
		}


	}
}